import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os
import sys
from ddt import ddt, file_data

# 怎么把public/common中的方法导入进来
pathmf = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))+"\\dataa\\datachengshifalse.json"
# 将其追加到sys.path
#sys.path.append(pathmf)
from mfxt.publick.common import houtaidenlu, houtaituichu, quitbrower

# 创建单元测试类
@ddt
class mifeng_dingdanguanli_list(unittest.TestCase):
    def setUp(self):
        # 创建浏览器对象
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.driver.get("http://39.101.167.251/qftest/index.php?m=backend")
        houtaidenlu(self.driver)

    @file_data(pathmf)
    def test_mifeng_dingdanguanli_updata(self, u, p, c, b, a, z, m, ca,expect):
        self.driver.find_element(By.LINK_TEXT, '订单管理').click()
        time.sleep(2)
        self.driver.find_element(By.LINK_TEXT, '订单列表').click()
        time.sleep(2)
        self.driver.switch_to.frame("main")
        time.sleep(2)
        # 直接点击订单号
        self.driver.find_element(By.LINK_TEXT, '426630004133092').click()
        time.sleep(2)
        # 点击修改信息按钮
        self.driver.find_element(By.XPATH, '/html/body/div/div[2]/div[3]/button[1]').click()
        # 收件人
        self.driver.find_element(By.NAME, 'receiver').clear()
        self.driver.find_element(By.NAME, 'receiver').send_keys(u)
        # 所在地区
        self.driver.find_element(By.NAME, 'province').clear()
        self.driver.find_element(By.NAME, 'province').send_keys(p)
        self.driver.find_element(By.NAME, 'city').clear()
        self.driver.find_element(By.NAME, 'city').send_keys(c)
        self.driver.find_element(By.NAME, 'borough').clear()
        self.driver.find_element(By.NAME, 'borough').send_keys(b)
        # 详细地址
        self.driver.find_element(By.NAME, 'address').clear()
        self.driver.find_element(By.NAME, 'address').send_keys(a)
        # 邮编
        self.driver.find_element(By.NAME, 'zip').clear()
        self.driver.find_element(By.NAME, 'zip').send_keys(z)
        # 手机号码
        self.driver.find_element(By.NAME, 'mobile').clear()
        self.driver.find_element(By.NAME, 'mobile').send_keys(m)
        # 修改原因
        self.driver.find_element(By.NAME, 'cause').clear()
        self.driver.find_element(By.NAME, 'cause').send_keys(ca)
        # 点击确定
        self.driver.find_element(By.XPATH, '//*[@id="pop-consignee"]/div/form/div/button[1]').click()

        # 断言
        expect_value = expect
        actual_value = self.driver.find_element(By.XPATH,'//*[@id="pop-consignee"]/div/form/table/tbody/tr[2]/td/span/font').text
        self.assertEqual(expect_value, actual_value, "预期和实际结果不一致！！")

        def tearDown(self):
            # 退出登录和关闭浏览器
            houtaituichu(self.driver)


if __name__ == '__main__':
    unittest.main()